<template>
	<view class="content">
		<scroll-view scroll-x class="tabs-content" enable-flex scroll-with-animation>
			<view class="order-nav">
				<view class="nav-item" v-for="(nav, index) in orderState" :key="index" @tap="onNav(index, nav.id)">
					<view class="item-title" :class="{ 'item-title-active': tabindex === index }">{{ nav.title }}</view>
					<view class="nav-line" :class="{ 'line-active': tabindex === index }"></view>
				</view>
			</view>
		</scroll-view>
		<mescroll-body ref="mescrollRef" height="1050" @init="mescrollInit" @down="downCallback" @up="upCallback">
			<view class="extension-box">
				<view class="extension-list">
					<view class="extension-item" v-for="(item, index) in resultList" :key="index">
						<view class="order-sn">
							<view class="left-sn">订单号：{{item.order_sn}}</view>
							<view class="right-status">{{item.status | statusFeilt}}</view>
						</view>
						<view
							style="width: 700upx;height: 1upx;background: #EEEEEE; margin: 0 auto; margin-top: 20upx;">
						</view>
						<view class="user-info">
							<view class="detail-left">
								<image :src="item.avatar"
									style="width: 76upx;height: 76upx;border-radius: 50%"></image>
								<view class="detail-no">
									<view class="">{{item.nickname}}</view>
									<view class="time">{{item.created_at}}</view>
								</view>
							</view>
							<view class="price">收入￥{{item.commission}}</view>
						</view>
					</view>
				</view>
			</view>
		</mescroll-body>
	</view>


</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";

	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				tabindex: 0,
				orderState: [{
						id: 0,
						title: '全部',

					},
					{
						id: 2,
						title: '待结算',
					},
					{
						id: 3,
						title: '已结算',
					},
				],
				page: 1,
				type: 0,
				resultList: [],
			};
		},
		filters: {
			statusFeilt(status) {
				let statusText;
				// -1 无效佣金 0预计佣金 1未结算  2已结算
				switch (status) {
					case -1:
						statusText = '无效佣金'
						break;
					case 0:
						statusText = '预计佣金'
						break;
					case 1:
						statusText = '未结算'
						break;
					case 2:
						statusText = '已结算'
						break;
				}
				return statusText;
			}
		},
		methods: {
			onNav(index, id) {
				if (this.tabindex !== index) {
					this.tabindex = index;
					this.type = id;
					this.downCallback();
				}
			},
			// 下拉刷新列表
			downCallback() {
				this.mescroll.resetUpScroll(); // 重置列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
			},
			/*上拉加载的回调*/
			upCallback(page) {
				this.page = page.num;
				this.$http.get('user.tuiguanList', {
					page: this.page,
					commission_type: this.type
				}).then(res => {
					let curPageData = res.data.data;
					let curPageLen = curPageData.length;
					let totalCount = res.data.total;
					if (page.num == 1) this.resultList = []; //如果是第一页需手动置空列表
					this.resultList = this.resultList.concat(curPageData); //追加新数据
					this.mescroll.endBySize(curPageLen, totalCount);
				})
			}
		},
	}
</script>

<style scoped lang="scss">
	@import './my-promotion-order.scss';
</style>
